import React, { useRef } from 'react';
import { connect } from 'umi';
import { useApplyManage } from '../common/useApplyManage';
import { SchemaManage } from '@/components/SchemaComponent';
import { ILoadMapTypeAll } from '@/common';
import { QC_SQSTATE, ZF_SQSTATE } from '../common/Format';
import { CancelModal } from '@/components/CancelTextModal';
import { ApplyManageAPI } from '../common/type';
import { RevokeModal } from '../../Acomponents/RevokeModal';

const ApplyManageView: React.FC<ApplyManageAPI.IManageType> = ({ curRes, locationProps }) => {
  const { tableProps, searchProps, actionList, isShowCancel, onChangeCancelModalState, onReloadManage, invalidState, setInvalidState } = useApplyManage({
    curRes,
    locationProps,
  });

  return (
    <div className={'apply-manage'}>
      {/* 管理页 */}
      <SchemaManage ref={useRef()} searchProps={searchProps} actionList={actionList} tableProps={tableProps as any} />

      {/* 作废弹窗 */}
      {isShowCancel?.isShow && (
        <CancelModal
          checkRows={isShowCancel?.resObj}
          cancelTypeDic={ILoadMapTypeAll.APPLY_CANCEL}
          cancelFormTypeRequired={true}
          cancelFormReasonRequired={true}
          modalTitle={'作废申请'}
          cancelText={isShowCancel?.resObj?.purchProjectName || null}
          cancelRequestUrl={'/purchaseApplyController/cancelApply'}
          reloadManage={onReloadManage}
          cancelRequestType="PUT"
          cancelRequestBody={{ state: ZF_SQSTATE(), cancelFlag: '0' }}
          onClose={() => onChangeCancelModalState({ isShow: false, resObj: null })}
        />
      )}

      {invalidState?.isShow && (
        <RevokeModal
          resObj={invalidState?.resObj}
          revokeRequestUrl={'/purchaseApplyController/invalid'}
          onClose={() => setInvalidState({})}
          reqBody={{ state: QC_SQSTATE() }}
          modalTip={
            <div style={{ color: '#000' }}>
              确认是否撤销【<span style={{ color: 'red' }}>{invalidState?.resObj?.applyTitle}</span>】的审核,撤销后可重新提交！
            </div>
          }
          reloadRequest={onReloadManage}
        />
      )}
    </div>
  );
};

export default connect(({ baseLogin }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
}))(ApplyManageView);
